home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / dev / basic / ace24dist.lha / ace24.lha / SUBmods / FontReq / FontReq.b < prev    next >
Text File  |  1996-09-11  |  3KB  |  132 lines

  1. {*
  2. ** ASL Font Requester for use in conjunction with ACE programs.
  3. **
  4. ** Author: David J Benn
  5. **   Date: 22nd January, 10th,13th February 1995,
  6. **       5th March 1995
  7. *}
  8.  
  9. {*
  10. ** General constants.
  11. *}
  12. CONST true = -1&, false = 0&
  13. CONST null = 0&
  14.  
  15. {*
  16. ** ASL contants/values.
  17. *}
  18. CONST ASL_FontRequest    = 1
  19.  
  20. CONST FONF_FRONTCOLOR     = 1
  21. CONST FONF_BACKCOLOR    = 2
  22. CONST FONF_STYLES    = 4
  23.  
  24. CONST TAG_DONE         = 0&
  25.  
  26. {*
  27. ** Structure definitions.
  28. *}
  29. STRUCT TagItem
  30.   LONGINT ti_Tag
  31.   LONGINT ti_Data
  32. END STRUCT
  33.  
  34. STRUCT TextAttr
  35.   ADDRESS  ta_Name
  36.   SHORTINT ta_YSize
  37.   BYTE       ta_Style
  38.   BYTE        ta_Flags
  39. END STRUCT
  40.  
  41. STRUCT FontRequester
  42.   ADDRESS  fo_Reserved1
  43.   ADDRESS  fo_Reserved2
  44.   TextAttr fo_Attr
  45.   BYTE       fo_FrontPen
  46.   BYTE       fo_BackPen
  47.   BYTE       fo_DrawMode
  48.   ADDRESS  fo_UserData
  49.   SHORTINT fo_LeftEdge
  50.   SHORTINT fo_TopEdge
  51.   SHORTINT fo_Width
  52.   SHORTINT fo_Height
  53. END STRUCT
  54.  
  55. STRUCT FontInfo
  56.   ADDRESS  fontName
  57.   SHORTINT fontHeight
  58.   SHORTINT textStyle
  59.   SHORTINT frontColor
  60.   SHORTINT backColor
  61. END STRUCT
  62.  
  63. {*
  64. ** Shared library function declarations.
  65. *}
  66. DECLARE FUNCTION ADDRESS AllocAslRequest(LONGINT type, ADDRESS ptags) LIBRARY asl
  67. DECLARE FUNCTION FreeAslRequest(ADDRESS request) LIBRARY asl
  68. DECLARE FUNCTION SHORTINT AslRequest(ADDRESS request, ADDRESS ptags) LIBRARY asl
  69.  
  70. DECLARE FUNCTION ADDRESS AllocateTagItems(LONGINT tags) LIBRARY utility
  71. DECLARE FUNCTION FreeTagItems(ADDRESS ptags) LIBRARY utility
  72.  
  73. {*
  74. ** Subprogram definitions.
  75. *}
  76. SUB LONGINT FontInfoRequest(ADDRESS theInfo) EXTERNAL
  77. DECLARE STRUCT TagItem *fontReqTags, *tag
  78. DECLARE STRUCT FontRequester *request
  79. DECLARE STRUCT TextAttr *theAttr
  80. DECLARE STRUCT FontInfo *info
  81. LONGINT ASL_FuncFlags, retVal
  82.  
  83.   LIBRARY "utility.library"
  84.   LIBRARY "asl.library"
  85.  
  86.   info = theInfo
  87.  
  88.   {* Allocate requester structure. *}
  89.   fontReqTags = AllocateTagItems(2)
  90.   IF fontReqTags = null THEN
  91.     retVal = false
  92.   ELSE
  93.     ASL_FuncFlags = SHL(1,31) + &H80000 + 20  {* see C header libraries/asl.h *}
  94.     tag = fontReqTags
  95.     tag->ti_Tag = ASL_FuncFlags
  96.     tag->ti_Data = FONF_FRONTCOLOR OR FONF_BACKCOLOR OR FONF_STYLES
  97.     tag = tag + SIZEOF(TagItem)
  98.     tag->ti_Tag = TAG_DONE
  99.  
  100.     request = AllocAslRequest(ASL_FontRequest, fontReqTags)
  101.  
  102.     IF request = null THEN 
  103.       retVal = false
  104.     ELSE
  105.       {* Render the requester. *}
  106.       IF AslRequest(request, null) THEN
  107.         {* Okay -> get font information. *}
  108.         theAttr = @request->fo_Attr
  109.         info->fontName = theAttr->ta_Name
  110.         info->fontHeight = theAttr->ta_YSize
  111.         info->textStyle = theAttr->ta_Style
  112.         info->frontColor = request->fo_FrontPen
  113.         info->backColor = request->fo_BackPen
  114.         retVal = true
  115.       ELSE
  116.         {* Requester cancelled. *}
  117.         retVal = false
  118.       END IF
  119.     END IF
  120.  
  121.     {* Clean up. *}
  122.     FreeAslRequest(request)
  123.     FreeTagItems(fontReqTags)
  124.  
  125.     LIBRARY CLOSE "asl.library"
  126.     LIBRARY CLOSE "utility.library"
  127.   END IF
  128.  
  129.   {* successful? *}
  130.   FontInfoRequest = retVal
  131. END SUB
  132.